﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;

namespace Dashboard.Models
{
	public class InstrumentView
	{
		[DisplayName("Network")]
		public string NetworkName { get; set; }
		[DisplayName("Serial number")]
		public string SerialNumber { get; set; }
		[DisplayName("Instrument")]
		public string Name { get; set; }
		[DisplayName("Connection speed (Kb/sec)")]
		public double? ConnectSpeed { get; set; }
		[DisplayName("Last synchronisation time")]
		public DateTime? LastSync { get; set; }
	}

	public class SystemConfigurationView
	{
		[DisplayName("Db connection string")]
		public string DB { get; set; }
		[DisplayName("Mosaic installation URL")]
		public string MosaicPro { get; set; }
		[DisplayName("ISIAdapter connection string")]
		public string ISIAdapterConnection { get; set; }
		[DisplayName("Infratec Adapter Port")]
		public string InfratecAdapterPort { get; set; }
	}

	public class UserView
	{
		[DisplayName("User name")]
		public string UserName { get; set; }
		[DisplayName("Last activity time")]
		public DateTime LastActivity { get; set; }
	}

	public class EventView
	{
		public bool IsWarning { get; set; }
		public string Text { get; set; }
		public DateTime OccuriedAtUTC { get; set; }
	}

	public class HealthView
	{
		public List<DateTimeDoubleValue> CpuUsage { get; set; }
		public List<DateTimeDoubleValue> CpuUsageAveraged { get; set; }
		public List<DateTimeDoubleValue> DiskUsage { get; set; }
		public List<DateTimeDoubleValue> DiskUsageAveraged { get; set; }
		public List<DateTimeDoubleValue> RamUsage { get; set; }
		public List<DateTimeDoubleValue> RamTotal { get; set; }
	}

	[Newtonsoft.Json.JsonConverter(typeof(DateTimeDoubleValueConverter))]
	public class DateTimeDoubleValue
	{
		public DateTimeDoubleValue(DateTime dateTimeValue, double doubleValue)
		{
			this.dateTimeValue = dateTimeValue;
			this.doubleValue = doubleValue;
		}

		[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.JavaScriptDateTimeConverter))]
		public DateTime dateTimeValue;
		public double doubleValue;
	}

	public class DateTimeDoubleValueConverter : Newtonsoft.Json.JsonConverter
	{
		static Newtonsoft.Json.Converters.JavaScriptDateTimeConverter jsDateConverter = new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter();

		public override bool CanConvert(Type objectType)
		{
			return objectType == typeof(DateTimeDoubleValue);
		}

		public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
		{
			throw new NotImplementedException();
		}

		public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
		{
			DateTimeDoubleValue dtValue = (DateTimeDoubleValue)value;
			writer.WriteStartArray();
			//jsDateConverter.WriteJson(writer, dtValue.dateTimeValue, serializer);
			writer.WriteRawValue(
				string.Format("Date.UTC(1970, 0, 1, {0}, {1}, {2}, {3})",
				dtValue.dateTimeValue.Hour,
				dtValue.dateTimeValue.Minute,
				dtValue.dateTimeValue.Second,
				dtValue.dateTimeValue.Millisecond));
			writer.WriteValue(dtValue.doubleValue);
			writer.WriteEndArray();
		}
	}

}